/**
 *
 * 事件传递助手
 * Created by ljg on 2017/2/22.
 */


export default function () {
    angular.module('ui.help').service('eventHelper', function ($templateCache) {
        /**
         * 向父级传递时间
         * @param $scope
         * @param object
         */
        this.upperNotice = function ($scope, event,param1,param2) {
            $scope.$emit(event, param1,param2);
        };

        /**
         * 向子级传递时间
         * @param $scope
         * @param object
         */
        this.downNotice = function ($scope, event,param1,param2) {
            $scope.$broadcast(event, param1,param2);
        };

    })
    angular.module('ui.help').service('ajaxHelper', function () {

        this.getJson = function (url,successFunc,failFunc) {
            $.ajax({
                url:url,
                type:"get",
                dataType:'json'
            }).done(function (result) {
                if(result.code=='0000'){
                    successFunc&&successFunc(result);
                }else {
                    failFunc&&failFunc(result);
                }
            }).fail(function (result) {
                toastr.error('服务器异常:'+result.statusText);

            });
        };


        this.postJson = function (url,param,successFunc,failFunc) {
            $.ajax({
                url:url,
                type:"post",
                data:param,
                dataType:'json'
            }).done(function (result) {
                if(result.code=='0000'){
                    successFunc&&successFunc(result);
                }else {
                    failFunc&&failFunc(result);
                }
            }).fail(function (result) {
                toastr.error('服务器异常:'+result.statusText);

            });
        };

    })
};

